﻿
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>云瑞家庭农场</title>
    <link rel="shortcut icon" href="~/Content/assets/i/miemie_favicon.ico" />
    <link href="~/Content/layui/css/layui.css" rel="stylesheet" />
    <script src="~/Content/layui/layui.js"></script>
    <script type="text/javascript" src="/Scripts/jquery-3.3.1.js"></script>
    <script type="text/javascript">
        layui.use(['form', 'layedit', 'laydate'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate;

            //日期
            laydate.render({
                elem: '#date'
            });
            laydate.render({
                elem: '#date1'
            });

            //创建一个编辑器
            var editIndex = layedit.build('LAY_demo_editor');

            $(document).ready(function () {
                var _token = cookie("token");
                $.ajax({
                    url: "/YunRuiFarmAPI/UserInfoGetMessageAPI", //请求的URL
                    cache: true, //不从缓存中取数据
                    data: {
                        "Token": _token,
                    }, //发送的参数
                    type: 'post', //请求类型
                    dataType: 'json', //返回类型是JSON
                    timeout: 20000, //超时
                })
                    .done(function (result) {
                        $("#Name").html("<img src= \"/Content/image/小埋1.jpg\" class=\"layui-nav-img\"/>" + result.Name)
                        $("#name").val(result.Name);
                        $("#sex").val(result.Sex);
                        var count = $("#sex option").length;//select下拉框的option条数
                        　　for (var i = 0; i < count; i++) {
                                if ($("#sex").get(0).options[i].text == result.Sex)          
                　　　　　　    {
                                    $("#sex").get(0).options[i].selected = true;
                    　　　　　　　　break;
                　　　　　　    }
            　　　　        }
                        $("#contacts").val(result.Contacts);
                        $("#username").val(result.Username);
                        $("#password").val(result.Password);
                    });
                $("#Cancellation").click(function () {
                    layer.msg("清除token");
                    delcookie("token", "", { expires: -1 });
                    window.location.href = "/YunRuiFarm/Login";
                });
                $("#Edit").click(function () {
                    var ui = document.getElementById("Save");
                    ui.style.display = "";
                    ui = document.getElementById("Cancel");
                    ui.style.display = "";
                    ui = document.getElementById("password-words");
                    ui.style.display = "";
                    ui = document.getElementById("password2");
                    ui.style.display = "";
                    ui = document.getElementById("Edit");
                    ui.style.display = "none";
                    document.getElementById("name").readOnly = false;
                    document.getElementById("sex").disabled = "";
                    document.getElementById("contacts").readOnly = false;
                    document.getElementById("username").readOnly = false;
                    document.getElementById("password").readOnly = false;
                });
                $("#Save").click(function () {
                    
                    var name = $("#name").val();
                    var sex = $("#sex option:selected").val();
                    var contacts = $("#contacts").val();
                    var username = $("#username").val();
                    var password = $("#password").val();
                    var password2 = $("#password2").val();
                    if (name.length < 1) {
                        layer.msg("请输入姓名");
                        return;
                    }
                    else if (username.length < 1) {
                        layer.msg("请输入用户名");
                        return;
                    }
                    else if (password.length < 6 || password.length > 12) {
                        layer.msg("密码必须6到12位");
                        return;
                    }
                    else if (password != password2) {
                        layer.msg("两次输入的密码不相同！");
                        return;
                    }
                    else {
                        $.ajax({
                            url: "/YunRuiFarmAPI/UserInfoSaveMessageAPI", //请求的URL
                            cache: true, //不从缓存中取数据
                            data: {
                                "Token": _token,
                                "Name": name,
                                "Sex": sex,
                                "Contacts": contacts,
                                "Username": username,
                                "Password": password,
                            }, //发送的参数
                            type: 'post', //请求类型
                            dataType: 'json', //返回类型是JSON
                            timeout: 20000, //超时
                        })
                            .done(function (result) {
                                $("#Name").html("<img src= \"/Content/image/小埋1.jpg\" class=\"layui-nav-img\"/>" + result.Name)
                                $("#name").val(result.Name);
                                $("#sex").val(result.Sex);
                                $("#contacts").val(result.Contacts);
                                $("#username").val(result.Username);
                                $("#password").val(result.Password);
                                layer.msg("保存成功");
                            });
                        var ui = document.getElementById("Save");
                        ui.style.display = "none";
                        ui = document.getElementById("Cancel");
                        ui.style.display = "none";
                        ui = document.getElementById("password-words");
                        ui.style.display = "none";
                        ui = document.getElementById("password2");
                        ui.style.display = "none";
                        ui = document.getElementById("Edit");
                        ui.style.display = "";
                        document.getElementById("name").readOnly = true;
                        document.getElementById("sex").disabled = true;
                        document.getElementById("contacts").readOnly = true;
                        document.getElementById("username").readOnly = true;
                        document.getElementById("password").readOnly = true;
                    }
                    
                });
                $("#Cancel").click(function () {
                    window.location.href = "/YunRuiFarm/UserInfo";
                });
                $("#power").click(function () {
                    $.ajax({
                        url: "/YunRuiFarmAPI/GetAdministratorsPower", //请求的URL
                        cache: true, //不从缓存中取数据
                        data: {
                            "Token": _token
                        }, //发送的参数
                        type: 'post', //请求类型
                        dataType: 'json', //返回类型是JSON
                        timeout: 20000, //超时
                        error: function (xhr, err) {
                            
                        },
                        success: function (result) {
                            if (result.IsSuccess)
                                window.location.href = result.Message;
                            
                        }
                    })
                });
            });
            function GetUrlPara() {
                var url = document.location.toString();
                var arrUrl = url.split("=");
                var para = arrUrl[1];
                return para;
            }
            function cookie(key, value, options) {
                if (typeof value === "undefined") {
                    var cookies = document.cookie.split("; ");
                    for (var i = 0, len = cookies.length; i < len; i++) {
                        var cookie = cookies[i].split("=");
                        if (decodeURIComponent(cookie[0]) === key) {
                            return decodeURIComponent(cookie[1]);
                        }
                    }
                    return null;
                }
            }
            function delcookie(key, value, options) {
                options = options || {};
                var cookie = encodeURIComponent(key) + "=" + value;
                if ((typeof options.expires) !== "undefined") {
                    if (typeof options.expires === "number") {
                        var days = options.expires,
                            t = options.expires = new Date();
                        t.setDate(t.getDate() + days);
                    }
                    cookie += ";expires=" + options.expires.toUTCString();
                }
                if (typeof options.path !== "undefined")
                    cookie += ";path=" + options.path;
                if (typeof options.domain !== "undefined")
                    cookie += ";domain=" + options.domain;
                if (options.secure)
                    cookie += ";secure";
                document.cookie = cookie;
            }
            function set_select_checked(selectId, checkValue) {
                
            }
        });

    </script>
    <script>
        layui.use('element', function () {
            var element = layui.element;
        });
        var url = document.location.toString();
        var arrUrl = url.split("=");
        var para = arrUrl[1];


    </script>
    <style>
        body {
            font-size: 18px;
        }

        #divtitle {
            margin: 0 auto;
            margin-top: 0px;
            margin-bottom: 0px;
        }

        
        #content-right {
            width: 100%;
            height: 100%;
            float: right
        }
        #content-right-top {
            margin-top: 2%;
            margin-right: 2%;
            margin-left: 2%;
            height: 20%;
            width: 96%;
            float: left
        }
        #content-right-button {
            margin-right: 2%;
            margin-left: 2%;
            margin-top: 1%;
            height: 64%;
            width: 96%;
            float: left;
            background-color: rgba(255,255,255,0.5);
        }
        #content-message {
            width:100%;
            height:75%;
            margin-top:5%;
            margin-left:10%
        }
        #content-button {
            width: 100%;
            height: 18%;
            margin-bottom: 2%;
        }
        #contactus-data {
            font-size: 14px;
        }
        img {
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body class="layui-layout-body">
    <div class="layui-layout layui-layout-admin">
        <div class="layui-header" style="width:auto">
            <div class="layui-logo" style=" background-image: url('../../Content/image/logo.jpg');background-size:100% 100%;"></div>
            <!-- 头部区域（可配合layui已有的水平导航） -->
            <ul class="layui-nav layui-layout-left" style="font-size: 20px;">
                <li class="layui-nav-item"><a href="/YunRuiFarm/Index">首页</a></li>
                <li class="layui-nav-item"><a href="/YunRuiFarm/Adopt">羊领养预约</a></li>
                <li class="layui-nav-item"><a href="/YunRuiFarm/Agricultural">农副产品预约</a></li>
                <li class="layui-nav-item"><a href="/YunRuiFarm/Restaurant">餐饮预约</a></li>
            </ul>
            <ul class="layui-nav layui-layout-right">
                <li class="layui-nav-item">
                    <a href="javascript:;" id="Name">
                        <img src="/Content/image/小埋1.jpg" class="layui-nav-img" />贤心
                    </a>
                    <dl class="layui-nav-child">
                        <dd><a href="/YunRuiFarm/UserInfo">基本资料</a></dd>
                        <dd><a href="/YunRuiFarm/UserGoatOrder">我的订单</a></dd>
                        <dd><a href="/YunRuiFarm/UserFeedback">反馈信息</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">账户操作</a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:;" id="power">切换到管理员</a></dd>
                        <dd><a href="javascript:;" id="Cancellation">注销</a></dd>
                    </dl>
                </li>
            </ul>
        </div>
        <div class="layui-side layui-bg-black">
            <div class="layui-side-scroll">
                <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
                <ul class="layui-nav layui-nav-tree" lay-filter="test">
                    <li class="layui-nav-item layui-nav-itemed">
                        <a class="" href="javascript:;">个人中心</a>
                        <dl class="layui-nav-child">
                            <dd><a href="/YunRuiFarm/UserInfo">个人信息</a></dd>
                            <dd><a href="/YunRuiFarm/UserGoatOrder">羊领养订单</a></dd>
                            <dd><a href="/YunRuiFarm/UserRestaurantOrder">餐饮订单</a></dd>
                            <dd><a href="/YunRuiFarm/UserAgriculturalOrder">农副产品订单</a></dd>
                            <dd><a href="/YunRuiFarm/UserFeedback">反馈</a></dd>
                        </dl>
                    </li>
                </ul>
            </div>
        </div>
        <div class="layui-body" style="background-color:#c0c0c0;height:100%;">
            <!-- 内容主体区域 -->


            <div id="content-right">
                <div id="content-right-top">
                    <img src="~/Content/image/grass.jpg" style="height:100%;" />
                </div>
                <div id="content-right-button">
                    <div id="content-message">
                        <div class="layui-form-item">
                            <label class="layui-form-label">姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" readonly="readonly" id="name">
                            </div>
                            <label class="layui-form-label">性别</label>
                            <div class="layui-input-inline" >
                                <select  style="width: 161px;height: 38px;" id="sex" disabled="true">
                                    <option value="3"selected="">未选择</option>
                                    <option value="2">男</option>
                                    <option value="1">女</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">联系电话</label>
                            <div class="layui-input-inline">
                                <input type="text" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" readonly="readonly" id="contacts">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">用户名</label>
                            <div class="layui-input-inline">
                                <input type="text" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" readonly="readonly" id="username">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">密码</label>
                            <div class="layui-input-inline">
                                <input type="text" lay-verify="required" placeholder="请填写6到12位密码" autocomplete="off" class="layui-input" readonly="readonly" id="password">
                            </div>
                            <label class="layui-form-label" hidden="hidden" style="display:none" id="password-words">确认密码</label>
                            <div class="layui-input-inline" hidden="hidden">
                                <input type="text" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" style="display:none" id="password2">
                            </div>
                        </div>

                    </div>
                    <div id="content-button">
                        <button class="layui-btn" lay-submit="" type="button" id="Edit" style="float:right;margin-right:40%;">编 辑</button>
                        <button class="layui-btn" lay-submit="" type="button" id="Cancel" style="float:right;margin-right:40%;display:none;">取 消</button>
                        <button type="button" class="layui-btn layui-btn-primary" id="Save" style="float:right;margin-right:2%;display:none;">保 存</button>
                    </div>
                </div>
            </div>
        </div>


    </div>
    <script>
        
    </script>
</body>
</html>
